<div id="consult">
    <div style="background: #EAEAEA;border: 1px solid #DFDFDF;border-top: 2px #ABABAB solid;">
        <div class="clearfix">
            <ul id="consult_category" class="clearfix" style="float: left;">
                <li class="current"><a href="javascript:;" data-id="0">全部购买咨询</a></li>
                <volist name="consult_category_list" id="category">
                    <li><a href="javascript:;" data-id="{$category.id}">{$category.title}</a></li>
                </volist>
            </ul>
            <if condition="check_auth('Addons/Consult/Consult/ask')">
                <div class="pull-right" style="margin-top: 5px;">
                    <a data-role="send_consult" style="padding: 5px 10px;margin: 10px;font-size: 15px;color: #4F8AD0;">发表咨询</a>
                </div>
            </if>
            <div id="consult-search" class="pull-right" style="line-height: 20px;margin-top: 3px;margin-right: 2px;">
                <div class="consult-pop">
                    <input type="text" id="consultSearchText" name="consult_keyword" placeholder="请输入关键词">
                    <input type="button" value="搜索" id="btnConsultSearch" class="btn-search">
                </div>
            </div>
        </div>
    </div>
    <div id="consult-wrap" style="border: 1px solid #DFDFDF;border-top: none;padding: 5px 10px;">
        <div class="prompt">
            <strong>{:L('_KINDLY_REMINDER_')}:</strong>
            <span>{$consult_tip}</span>
        </div>
    </div>
    <div id="consult-list" style="border: 1px solid #F5F5F5;border-top: none;padding: 13px;">
        {$list_content}
    </div>
</div>
<style>
    #consult ul {
        margin-bottom: 0px;
        list-style: none;
    }

    #consult li {
        float: left;
        padding: 5px 10px;
    }

    #consult li.current {
        padding: 11px 10px 6px;
        margin: -6px 0 -1px -1px;
        background: white;
        border-left: 1px solid #DFDFDF;
        border-right: 1px solid #DFDFDF;
        border-top: 2px solid #4F8AD0;
    }
    #consult li.current a{
        text-decoration: none;
    }
    #consult-list .item{
        padding: 8px 0;
        border-bottom: 1px dotted #DEDEDE;
    }
    #consult-list .item .user{
        margin-top: 0;
        color: #9C9A9C;
    }
    #consult-list .item .user span{
        margin-right: 10px;
    }
    #consult-list .item dl{
        margin-bottom: 5px;
        margin-top: 5px;
    }
    #consult-list .item dt{
        float: left;
        width: 65px;
    }
    #consult-list .item dd{
        margin-left: 65px;
    }
</style>
<script>
    var consult_info={
        table_name:"{$consult_info['table_name']}",
        row_id:"{$consult_info['row_id']}",
        limit:"{$consult_info['limit']}",
        goods_uid:"{$consult_info['goods_uid']}",
        tab_url:"{:addons_url('Consult://Consult/consult')}",
        show_more_url:"{:addons_url('Consult://Consult/consultMore')}",
        delete_url:"{:addons_url('Consult://Consult/delete')}",
        from_url:"{$consult_info['from_url']}",
        type_id:0,
        ask_url:"{:addons_url('Consult://Consult/ask')}",
        answer_url:"{:addons_url('Consult://Consult/answer')}",
        keyword:''
    };
    $(function(){
        $('#consult_category li').each(function(){
            $(this).click(function(){
                $('#consult_category li').removeClass('current');
                $(this).addClass('current');
                consult_info.type_id=$(this).find('a').attr('data-id');
                $('#consultSearchText').val('');
                consult_info.keyword='';
                $.post(consult_info.tab_url,{table_name:consult_info.table_name,row_id:consult_info.row_id,limit:consult_info.limit,type_id:consult_info.type_id},function(msg){
                    $('#consult-list').html(msg.html);
                    $('#consult-wrap span').html(msg.tip);
                },'json');
            });
        });
        $('#btnConsultSearch').click(function(){
            consult_info.keyword=$('#consultSearchText').val();
            $.post(consult_info.tab_url,{table_name:consult_info.table_name,row_id:consult_info.row_id,limit:consult_info.limit,type_id:consult_info.type_id,consult_keyword:consult_info.keyword},function(msg){
                $('#consult-list').html(msg.html);
            },'json');
        });
        var show_more="{$show_more}";
        if(show_more){
            consult_info.now_page=1;
            $('[data-role="consult_show_more"]').click(function(){
                $.post(consult_info.tab_url,{table_name:consult_info.table_name,row_id:consult_info.row_id,limit:consult_info.limit,type_id:consult_info.type_id,consult_keyword:consult_info.keyword},function(msg){
                    $('#consult-list').html(msg.html);
                },'json');
            });
        }
        consult_function.bind_send();
    });
    var consult_function={
        bind_send:function(){
            $('[data-role="send_consult"]').unbind('click');
            $('[data-role="send_consult"]').click(function(){
                var myModalTrigger = new ModalTrigger({
                    'type':'ajax',
                    'url':consult_info.ask_url+'&table_name='+consult_info.table_name,
                    'title':'购买咨询'
                });
                myModalTrigger.show();
            });
        },
        bind_answer:function(){
            $('[data-role="consult_answer"]').unbind('click');
            $('[data-role="consult_answer"]').click(function(){
                var consult_id=$(this).attr('data-id');
                var myModalTrigger = new ModalTrigger({
                    'type':'ajax',
                    'url':consult_info.answer_url+'&consult_id='+consult_id,
                    'title':'回复咨询'
                });
                myModalTrigger.show();
            });
        },
        bind_delete:function(){
            $('[data-role="consult_delete"]').unbind('click');
            $('[data-role="consult_delete"]').click(function(){
                var consult_id=$(this).attr('data-id');
                var $that=$(this);
                $.post(consult_info.delete_url,{consult_id:consult_id},function(msg){
                    if(msg.status){
                        toast.success('删除成功！');
                        $that.parents('.item').hide();
                    }else{
                        handleAjax(msg);
                    }
                },'json');
            });
        }
    };
</script>